<script>
$j(function() {
	switchtype();
});
function switchtype() {
	var type = $j('#pricetype').val();
	if(type == 1) { $j('#pt-title').html('Cost per kilo'); }
	else if(type == 2) { $j('#pt-title').html('Fixed price'); }
}
function addcond(n) {
	n++;
	$j('#plus').html('<input type="button" class="button rounded" value="+" onclick="addcond(' + n + ')" />');
	$j('#conditions').append('<dl class="four" id="cond-' + n + '"><dt>&nbsp;</dt><dd><input type="text" class="textfield rounded" name="prices[]" /></dd><dd>if they spend more than</dd><dd class="small"><input type="text" class="textfield rounded" name="conditions[]" /></dd><dd id="minus-' + n + '" class="sign"><input type="button" class="button rounded" value="&ndash;" onclick="removecond(' + n + ')" />');
}
function removecond(n) {
	$j('#cond-' + n).remove();
}
</script>
    	<div class="left">
        	<h1>System Settings</h1>
            <div class="bar">
            	<div class="text">Shipping Methods &raquo; Edit Shipping Method</div>
            	<div class="cr"></div>
            </div>
            <div class="box">
            	<input type="button" class="button rounded" value="Back to Shipping Methods List" onclick="history.go(-1)" />
            </div>
            <hr />
            <form method="post" action="<?=base_url()?>admin/system/updateshippingmethod">
            <input type="hidden" name="shipping_id" value="<?=$shipping['id']?>" />
            <div class="box bgw">
            	<h3>Basic Information</h3>
                <p class="desc">Please enter following information to update new shipping methods for your shopping cart.</p><br />
                <dl class="two"><dt>Method name</dt><dd><input type="text" class="textfield rounded" name="name" value="<?=$shipping['name']?>" /></dd></dl>
                <dl class="two"><dt>Description</dt><dd><input type="text" class="textfield rounded" name="description" value="<?=$shipping['description']?>" /></dd></dl>                
                <dl></dl>
             </div>
            <hr />
            <div class="box">
                <h3>Shipping Cost</h3>
                <dl class="four"><dt>Price type</dt><dd>
                    <select name="price_type" id="pricetype" onchange="switchtype()">
                        <option value="1"<?php if($shipping['price_type'] == 1) print ' selected="selected"'; ?>>Based of weight</option>
                        <option value="2"<?php if($shipping['price_type'] == 2) print ' selected="selected"'; ?>>Flat rate</option>
                    </select>
                </dd><dd><input type="text" class="textfield rounded" name="price_value" value="<?=$shipping['price_value']?>" /></dd><dd id="pt-title">Cost per kilo</dd></dl>
                <dl class="four"><dt>&nbsp;</dt><dd><p class="desc">With the set price shipping method you can set 2 parameters. The set price dollar amount and the<br />condition for when this will be applied such as when a user spends more than $50 a set price will be<br /> applied such as $5</p></dd></dl>
                <div id="conditions">
                <dl class="four" id="cond-0"><dt>Add condition</dt><dd><input type="text" class="textfield rounded" name="prices[]" value="<?=$conditions[0]['price']?>" /></dd><dd>if they spend more than</dd><dd class="small"><input type="text" class="textfield rounded" name="conditions[]" value="<?=$conditions[0]['condition']?>" /></dd><dd id="plus" class="sign"><input type="button" class="button rounded" value="+" onclick="addcond(<?=(count($conditions)-1)?>)" /></dd></dl>
                <?php for($i=1;$i<count($conditions);$i++) { ?>
                <dl class="four" id="cond-<?=$i?>"><dt>&nbsp;</dt><dd><input type="text" class="textfield rounded" name="prices[]" value="<?=$conditions[$i]['price']?>" /></dd><dd>if they spend more than</dd><dd class="small"><input type="text" class="textfield rounded" name="conditions[]" value="<?=$conditions[$i]['condition']?>" /></dd><dd id="minus-<?=$i?>" class="sign"><input type="button" class="button rounded" value="&ndash;" onclick="removecond(<?=$i?>)" /></dd></dl>
                <?php } ?>
                </div>
                <dl></dl>
            </div>
            <hr />
            <div class="box bgw">
                <h3>Locations</h3>
                <dl class="two"><dt>Available countries</dt><dd>
                    <select name="countries[]" multiple="multiple" size="10" style="height:auto;">
                    <?php foreach($countries as $ct) { ?>
                        <option value="<?=$ct['id']?>"<?php if($this->System_model->shipping_country($shipping['id'],$ct['id'])) print ' selected="selected"'; ?>><?=$ct['name']?></option>
                    <?php } ?>
                    </select>
                </dd></dl>
                <dl></dl>
            </div>
            <hr />
            <div class="box">
                <dl class="four"><dt>&nbsp;</dt><dd><input type="submit" class="button rounded" value="Update method" /></dd><?php if($this->session->flashdata('updated')) { ?><dd class="green">This shipping method has been updated successfully</dd><?php } ?></dl>
                <dl></dl>                
            </div>
            </form>
        </div>
        
